#ifndef SDICAPTURE_H
#define SDICAPTURE_H



#include <QWidget>
#include <QThread>
#include <QStringList>
#include "ldCommon.h"

#include <linux/videodev2.h>
#include <rga/RockchipRga.h>
#include <QImage>

#include <rga/im2d.hpp>
#include <rga/im2d_type.h>
#include <rga/RgaUtils.h>
#include <rga/rga.h>


class SdiCatprue: public QThread
{
    Q_OBJECT
public:
    explicit  SdiCatprue(QObject *parent);
    ~SdiCatprue();


    void    run()  override;
    void    Stop();



    int     GetFps() {int nRes = m_nFps; m_nFps = 0; return nRes; }

    void    init_rga();
    void    init_display_buf();
    void    init_mmap(void);
    void    init_device(void);
    int     read_frame(stVFrame*  pFrame);
signals:
    void    ProcFrame(stVFrame* newFrame);

private:
    QObject*            m_parent;
    volatile int        m_ThreadRun;
    uint8_t*            m_pTmpFrame;
    uint8_t*            m_pScaleYUV;

    volatile int        m_nFps;
    volatile int        m_nFps_tv;
    volatile int        m_nFps_ir;
    volatile int        m_nFrameCnt;

    int                 m_nVisibleWidth;
    int                 m_nVisibleHeight;

    int                 m_nInfraredWidth;
    int                 m_nInfraredHeight;

    int                 m_nOutWidth;
    int                 m_nOutHeight;

   volatile  uint8_t             ucVideoCtrl2;

    int                 SelectGetFrame();

    void                CapInitAlgV4l2(int nChn);


    static unsigned int n_buffers;


    int first = 0;
    int fd = -1;
    RockchipRga *rga;

    rga_info_t rga_info_src;
    rga_info_t rga_info_dst;
    char *cap_buf[BUFFER_COUNT];

    char *resize1024x768_buf;
    char *resize1440x1080_buf;

    int cap_dma_fd[BUFFER_COUNT], video_dma_fd, resize1440x1080_fd, resize1080x768_fd;
    rga_buffer_t src[BUFFER_COUNT] = {};
    rga_buffer_t video = {};
    rga_buffer_t resize1440x1080 = {};

    rga_buffer_t resize1080x768 = {};

    rga_buffer_handle_t cap_handle[BUFFER_COUNT], video_handle,resize1440x1080_handle , resize1024x768_handle;

    int cap_width, cap_height, cap_format;
    int resize_width, resize_height, resize_format;
    int video_width, video_height, video_format;
    int cap_buf_size, video_buf_size,resize_buf_size;


    volatile int    m_nSeq;

    stVFrame     m_VFrame[MAX_FRAME_BUFF_CNT];

};


#endif // SDICAPTURE_H
